<?php
namespace Application\Repository;
use Doctrine\ORM\EntityRepository;

class AbstractRepository extends EntityRepository
{
   protected $table;
    
    public function getByCreatedAt($createdAtStart, $createdAtEnd,$number = 100)
    {
    	$dql = "SELECT c FROM $this->table c WHERE c.created_at between ?1 and ?2";
    
    	return $this->getEntityManager()->createQuery($dql)
    	->setParameter(1, $createdAtStart)
    	->setParameter(2, $createdAtEnd)
    	->setMaxResults($number)
    	->getResult();
    }
    
    public function listFromMin($minId, $maxResult=null, $excludeMin=true)
    {
    	$quantifier = $excludeMin?">":">=";
		$dql = "SELECT c FROM $this->table c WHERE c.id ".$quantifier." ?1 order by c.id asc";
		
		$query = $this->getEntityManager()->createQuery($dql)
    	->setParameter(1, $minId);
    	if($maxResult!=null && $maxResult>0) $query->setMaxResults($maxResult);
    	return $query->getResult();
    }
    
    public function getByModifiedAt($modifiedAtStart, $modifiedAtEnd,$number = 100)
    {
    	$dql = "SELECT c FROM $this->table c WHERE c.modified_at between ?1 and ?2";
    
    	return $this->getEntityManager()->createQuery($dql)
    	->setParameter(1, $modifiedAtStart)
    	->setParameter(2, $modifiedAtEnd)
    	->setMaxResults($number)
    	->getResult();
    }
}